package com.easylinkin.linkappapi.quality.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.quality.entity.ActualMeasureItem;
import com.easylinkin.linkappapi.quality.service.ActualMeasureItemService;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.util.List;

/**
 * ActualMeasureItem表控制层
 *
 * @author zhengwen
 * @date 2022/08/30
 */
@RestController
@RequestMapping("/actualMeasureItem")
public class ActualMeasureItemController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private ActualMeasureItemService appQualityActualMeasureItemService;

    /**
     * 分页查询所有数据
     *
     * @param requestModel 查询分页对象
     * @return 所有数据
     */
    @PostMapping("getPage")
    @ApiOperation("查询分页")
    public RestMessage selectPage(@RequestBody RequestModel<ActualMeasureItem> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<ActualMeasureItem> record = appQualityActualMeasureItemService.selectPage(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder(record).build();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation("查询单条")
    public RestMessage selectOne(@PathVariable Serializable id) {
        return RestBuilders.successBuilder((this.appQualityActualMeasureItemService.getOneById(id))).build();
    }

    /**
     * 新增数据
     *
     * @param appQualityActualMeasureItem 实体对象
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation("新增")
    public RestMessage insert(@RequestBody ActualMeasureItem appQualityActualMeasureItem) {
        return RestBuilders.successBuilder().success((this.appQualityActualMeasureItemService.saveOne(appQualityActualMeasureItem))).build();
    }

    /**
     * 修改数据
     *
     * @param appQualityActualMeasureItem 实体对象
     * @return 修改结果
     */
    @PutMapping
    @ApiOperation("修改单条")
    public RestMessage update(@RequestBody ActualMeasureItem appQualityActualMeasureItem) {
        return RestBuilders.successBuilder().success(this.appQualityActualMeasureItemService.updateOne(appQualityActualMeasureItem)).build();
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    @ApiOperation("批量删除")
    public RestMessage delete(@RequestParam("idList") List<Long> idList) {
        return RestBuilders.successBuilder().success(this.appQualityActualMeasureItemService.deleteByIds(idList)).build();
    }

    @PostMapping("export")
    @ApiOperation("导出")
    public void export(@RequestBody ActualMeasureItem appQualityActualMeasureItem, HttpServletRequest request, HttpServletResponse response) {
        appQualityActualMeasureItemService.export(appQualityActualMeasureItem, request, response);
    }
}

